<?php
include_once('common/header.php');	
if($AppUI->id <= 0 || !isset($_SERVER['HTTP_REFERER'])) {	
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intHexId		= $objRequest->getParam('uid',0);
$intType		= $objRequest->getParam('type',0);
$strToken		= $objRequest->getParam('token','');
$strTok			= $intHexId . '_' . $AppUI->id;
$strSession		= isset($_SESSION['relation' . $strTok]) ? $_SESSION['relation' . $strTok] : '';
$intError		= 0;
$strFullname	= '';
$intRday		= RELATION_TIME;
if($intHexId && Vfriend_Function::isValidLink($strRefer) && $strToken != '' && $strSession != '' && $strSession == $strToken) {
	unset($_SESSION['relation' . $strTok]);
	$objVfriendUser	= new Vfriend_User();
	$objUser		= $objVfriendUser->getInfoByHexUserId($intHexId);
	if($objUser->id != $AppUI->id && $objUser) {
		$strFullname	= $objUser->fullnamevn;
		$objURequest	= new URequest();
		$intError		= $objURequest->addRelation($AppUI->id,$objUser->id,$intType,$intRday);
		if($intError == 0) {
			$strMessage	= $arrMessage[$intType];
			$strMessage	= str_replace('[strFullname]',$strFullname,$strMessage);
			Vfriend_Function::setMsg($strMessage);
		}elseif($intError == 1) {
			$intError = $intType + 6;
		}elseif($intError == 2) {
			if($intType == 4) $intError = 13;
			elseif($intType == 5) $intError = 14;
		}elseif($intError == 3) $intError = 40;
	} else {
		$intError = 6;
	}
} else {
	$intError	= 1;
}
if($intError > 0) {
	$strError	= $arrError[$intError];
	$strError	= str_replace('[strFullname]',$strFullname,$strError);
	$strError	= str_replace('[intDay]',$intRday,$strError);	
	Vfriend_Function::setError($strError);
}
Vfriend_Function::redirect(isset($strRefer) ? $strRefer : HOST_VFRIEND);
?>